<?php
namespace app\common\entity;

use think\Db;
use think\Model;
use app\common\entity\LegalConfig;


class LegalReturnlog extends Model
{
    protected $table = 'legal_returnlog';

    const TYPE_BUY = 1; //买入订单
    const TYPE_SALE = 2; //卖出订单

    const STATUS_PAY = 1; //等待付款
    const STATUS_CONFIRM = 2; //等待确认付款
    const STATUS_FINISH = 3; //订单完成

    const STATUS_CANCEL = -1; //取消付款
    const STATUS_ERROR = -2; //错误订单

    public function getStatus()
    {
        switch ($this->status) {
            case self::STATUS_PAY:
                return '等待付款';
            case self::STATUS_CONFIRM:
                return '等待收款';
            case self::STATUS_FINISH:
                return '交易完成';
            case self::STATUS_CANCEL:
                return '取消付款';
            case self::STATUS_ERROR:
                return '错误订单';
            default:
                return '';

        }
    }


   
    public function returnmoney()
    {   
        //查询所有会员
        $alluser = User::where('coin', '>',0)->where('cointime', '>',0)->select();
        
        $LegalConfig = new LegalConfig();

        //释放比例
        $returnratio = $LegalConfig->getValue('releaseratio');


        foreach ($alluser as $value) {

            $returnmoney = floor($value['coin'] * $returnratio) / 100;
            $arr = [
                'user_id'=> $value['id'],
                'returnmoney'=> $returnmoney,
                'returnratio'=>$returnratio,
                'qian'=>$value['coin'],
                'hou'=> bcsub($value['coin'],$returnmoney),
                'surplusday'=>$value['cointime']-1,
                'createtime'=>time()
            ];
            
        }
        unset($value);
    }
   

 
}
